//
//  PartyLearningController.m
//  village_ios
//
//  Created by mac on 2019/8/5.
//  Copyright © 2019 com.sw.village. All rights reserved.
//

#import "PartyManagerController.h"
#import "ArticleListController.h"

@interface PartyManagerController ()

@property (strong, nonatomic) NSMutableArray *menuList;
@property (strong, nonatomic) IBOutlet UICollectionView *menuCollectionView;

@end

@implementation PartyManagerController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupInit];
    
}
- (void)setupInit {
    
    
    self.menuList = [NSMutableArray array];
   
    
    //data
    NSArray *indexMenusList = [[MenuManager sharedInstance] menusDictM][@"dangwuguanli"];
    self.menuList = [MenuItem mj_objectArrayWithKeyValuesArray:indexMenusList];
    [self.tableView reloadData];
    [self.menuCollectionView reloadData];
    
}

#pragma mark - UICollectionView

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    if (collectionView == self.menuCollectionView) {
        return self.menuList.count;
    }
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (collectionView == self.menuCollectionView) {
        MenuCollectionViewCell * cell = (MenuCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"MenuCollectionViewCell" forIndexPath:indexPath];
        MenuItem *item = self.menuList[indexPath.row];
        cell.menuItem = item;
        return cell;
    }
    return nil;
    
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    MenuItem *item = [[MenuItem alloc]init];
    if (collectionView == self.menuCollectionView){
        item = self.menuList[indexPath.row];
    }
    if([item.router isEqualToString:@"ArticleList"]) {
        ArticleListController *vc = [ArticleListController instanceWithStoryBoard];
        vc.menuItem = item;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        NSString *vcname = [NSString stringWithFormat:@"%@Controller",item.router];
        id vc = [NSClassFromString(vcname) instanceWithStoryBoard];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

@end
